package com.henz.web.util;


import java.util.Map;
import java.util.Set;

import org.json.JSONObject;

import com.google.appengine.api.channel.ChannelMessage;

public class ChannelUtil {
	
	public static void main(String args[])throws Exception{
		System.out.println( getChannelMessage("", "ajfdl") );
	}
	
	public static ChannelMessage getChannelMessage( String channelId, String message )throws Exception{
		ChannelMessage returnValue = null;
		JSONObject messageObj = null;
		
		messageObj = new JSONObject();
		
		messageObj.put("message", message);
		
		returnValue = getChannelMessage(channelId, messageObj);
		
		return returnValue;
	}
	
	public static ChannelMessage getChannelMessage( String channelId, Map<String, Object> messageMap )throws Exception{
		ChannelMessage returnValue = null;
		
		JSONObject messageObj = null;
		messageObj = new JSONObject();
		
		Set<String> keySet = null;
		Object value = null;
		
		keySet = messageMap.keySet();
		for(String key:keySet){
			value = messageMap.get(key);
			messageObj.put(key, value);
		}
		
		returnValue = getChannelMessage(channelId, messageObj);
		
		return returnValue;
	}
	
	public static ChannelMessage getChannelMessage( String channelId, JSONObject messageObj )throws Exception{
		ChannelMessage returnValue = null;
		String message = null;
		
		message = messageObj.toString();
		
		returnValue = new ChannelMessage(channelId, message);
		
		return returnValue;
	}
	
	
}
